﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Procedure = DeltaFlex.Data.ConsProcedures.Concepte_Albara;

namespace DeltaFlex.Data
{
    public class Concepte_Albara
    {
        public Concepte_Albara()
        { }

        #region Inserts
        public static int InsertarConcepte_Alabara(int idAlbara, int idArticle, decimal quantitat, string strSuperficie, decimal decimalSuperficie, 
                                                   string unitats, decimal pvp, decimal import)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = Procedure.SP_INSERTARCONCEPTE_ALBARA;

            cmd.Parameters.AddWithValue(Procedure.PARAMETE_IDALBARA, idAlbara);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_IDARTICLE, idArticle);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_QUANTITAT, quantitat);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_STRSUPERFICIE, strSuperficie);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_DECIMALSUPERFICIE, decimalSuperficie);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_UNITATS, unitats);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_PVP, pvp);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_IMPORT, import);

            return Operacions_BD.Insertar(cmd);
        }

        #endregion

        #region Update
        public static void ActualitzarConcepteAlbara(int idConcepte_Albara, int idArticle, decimal quantitat, string strSuperficie,
                                                      decimal decimalSuperficie, string unitats, decimal pvp, decimal import)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = Procedure.SP_ACTUALITZAR_CONCEPTE_ALBARA;

            cmd.Parameters.AddWithValue(Procedure.PARAMETRE_IDCONCEPTE_ALBARA, idConcepte_Albara);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_IDARTICLE, idArticle);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_QUANTITAT, quantitat);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_STRSUPERFICIE, strSuperficie);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_DECIMALSUPERFICIE, decimalSuperficie);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_UNITATS, unitats);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_PVP, pvp);
            cmd.Parameters.AddWithValue(Procedure.PARAMETE_IMPORT, import);

            Operacions_BD.Update(cmd);

        }
        #endregion

        #region Selects
        public static IDataReader LlistarConcepte_Albarans(int idAlbara)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = Procedure.SP_CERCARCONCEPTE_ALBARABYIDALBARA;

            cmd.Parameters.AddWithValue(Procedure.PARAMETE_IDALBARA, idAlbara);

            return Operacions_BD.Reader(cmd);
        }

        #endregion
    }
}
